package com.fyzk.activity.prize.item;

import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Html;
import android.text.Spanned;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.fyzk.activity.app.App;
import com.fyzk.data.AppLotteryInfos;
import com.fyzk.utils.AppUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.tyjc.lottery.R;

public class QXCPrizeItem extends PrizeItemBase implements
		PrizeNumFormatInterface {

	@Override
	public String getLotteryName() {
		return AppLotteryInfos.getLotteryName(LotteryIDUtils.QXC_LOTTERY_ID_INT);
	}

	@Override
	public int getLogoResID() {
		return R.drawable.main_qixingcai;
	}
	
	@Override
	public Spanned formatPrizeNumSpanned() {
		String prizeNum = this.getPrizeNum();
		String[] prizeNums = prizeNum.split(",");
		StringBuffer stb = new StringBuffer();
		for (int i = 0; i < prizeNums.length; i++) {
			try {
				String num = prizeNums[i];
				stb.append("<font color=\"");
				stb.append(PrizeItemBase.COLOR_RED);
				stb.append("\">");
				stb.append(num + "&nbsp");
				stb.append("</font>");
			} catch (Exception e) {
				stb.append("<font color=\"");
				stb.append("数据错误");
				stb.append("\">");
			}
		}
		return Html.fromHtml(stb.toString());
	}

	@Override
	public Spanned formatPrizeNumSpanned(String str) {
		String num = "09,01,04,05,06,07,09";
		return Html.fromHtml(num);
	}

	@Override
	public void initNumView(View view) {
		LinearLayout layout = (LinearLayout) view;
		layout.removeAllViews();
		String prizeNum = this.getPrizeNum();
		String[] nums = prizeNum.split(",");
		int arr_length = nums.length;
		int width = AppUtil.dip2px(App.getContext(), 30);
		for (int i = 0; i < arr_length; i++) {
			String num = nums[i];
			TextView mTxt_ball = new TextView(App.getContext());
			LayoutParams layoutParams = new LayoutParams(width, width);

			mTxt_ball.setLayoutParams(layoutParams);
			mTxt_ball.setGravity(Gravity.CENTER);
			mTxt_ball.setTextColor(Color.WHITE);
			mTxt_ball.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
			mTxt_ball.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗
			mTxt_ball.setText(num);
			if (i != 0) {
				layoutParams.setMargins(15, 0, 0, 0);
			}
			mTxt_ball.setBackgroundResource(R.drawable.dot_ball_red);

			layout.addView(mTxt_ball);
		}
	}

}
